package com.jbarreto.vc.actions;

import javax.servlet.http.*;
import org.apache.struts.action.*;

import com.jbarreto.utils.SuggestionUtils;
import com.jbarreto.vc.forms.RegistrationForm;

public class RegisterAction2 extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		RegistrationForm registrationForm = (RegistrationForm) form;

		String email = registrationForm.getEmail();
		String password = registrationForm.getPassword();

		if (email != null
				&& (email.trim().length() < 3 || !email.contains("@"))) {
			request.setAttribute("suggestionBean", SuggestionUtils
					.getSuggestionBean());
			return mapping.findForward("bad-address");
		}

		if (password != null && password.trim().length() < 6) {
			request.setAttribute("suggestionBean", SuggestionUtils
					.getSuggestionBean());
			return mapping.findForward("bad-password");
		}

		return mapping.findForward("success");
	}
}
